package com.caozf.io.nio;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.util.UUID;

/**
 * 创建时间：2019/11/2 20:07
 * 创建人:曹子方
 */
public class ClientSocketDemo {
    public static void main(String[] args) {
        try (Socket socket=new Socket("127.0.0.1",8080);
             OutputStream out=socket.getOutputStream();
             DataInputStream dataInputStream=new DataInputStream(socket.getInputStream());
        ){
            String uuid= UUID.randomUUID().toString();
            out.write(uuid.getBytes());
            System.out.println("客户端发送数据：" + uuid);
            byte[] bytes=new byte[1024];
            int len=dataInputStream.read(bytes);
            if(len>0){
                System.out.println(new String(bytes,0,len));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
